package com.file.manage.infrastructure.dao.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.file.manage.domain.entity.File;
import com.file.manage.domain.entity.User;
import com.file.manage.infrastructure.base.dao.impl.BaseDaoImpl;
import com.file.manage.infrastructure.dao.FileDao;
import com.file.manage.infrastructure.mapper.FileMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author H41
 * @Type IFileDaoImpl.java
 * @date 2025/5/31 12:26
 * @Desc
 */
@Repository
public class FileDaoImpl extends BaseDaoImpl<FileMapper, File> implements FileDao {

    @Override
    public File selectByParentIdAndName(String parentId, String name) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<File>()
                .isNull(StrUtil.isBlank(parentId), File::getParentId)
                .eq(StrUtil.isNotBlank(parentId), File::getParentId, parentId)
                .eq(File::getName, name)
                .orderByDesc(File::getCreatedTime));
    }

    @Override
    public List<File> selectByParentId(String parentId) {
        return this.baseMapper.selectList(new LambdaQueryWrapper<File>()
                .isNull(StrUtil.isBlank(parentId), File::getParentId)
                .eq(StrUtil.isNotBlank(parentId), File::getParentId, parentId)
                .orderByDesc(File::getCreatedTime));
    }

}
